package com.miyake.client;

import com.miyake.client.GoogleLoginComposite.LoginHandler;
import com.miyake.client.SelectionBarComposite.SelectionBarHandler;
import com.miyake.client.community.CommunityMain;
import com.miyake.client.datamanage.DataManageMain;
import com.miyake.client.profile.ProfileMain;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class DoctorsSNS implements EntryPoint {
	private final String textTop = "Top";
	private final String textProfile = "Profile";
	private final String textMyData = "My Data";
	private final String textFriends = "Friends";
	private final String textCommunity = "Community";
	private final String textMessage = "Message";
	
	private RootPanel mainPanel = RootPanel.get("mainContainer");
	
	private DataManageMain dataManage = null;
	private ProfileMain profile = null;
	private CommunityMain communityMain = null;
	private TopPage top = null;
	
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		final GoogleLoginComposite loginComposite = new GoogleLoginComposite();
		loginComposite.addLoginHandler(new LoginHandler() {
			@Override
			public void onLogin(boolean login) {
				if (login) {					
					SelectionBarComposite buttonComposite = new SelectionBarComposite();
					buttonComposite.addButton(textTop);
					buttonComposite.addButton(textProfile);
					buttonComposite.addButton(textMyData);
					buttonComposite.addButton(textCommunity);
					buttonComposite.addButton(textMessage);
					RootPanel.get("buttonContainer").add(buttonComposite);
					buttonComposite.addSelectionBarHandler(new SelectionBarHandler() {
						@Override
						public void onSelect(String name) {
							clearMainPanel();
							if (name.equals(textTop)) {
								showTop();
							}
							else if (name.equals(textProfile)) {
								showProfile();
							}
							else if (name.equals(textMyData)) {
								showMyData();
							}
							else if (name.equals(textCommunity)) {
								showCommunity();
							}
							else if (name.equals(textMessage)) {
								showMessage();
							}
							else if (name.equals(textFriends)) {
								showFriends();
							}
						}
					});
					showTop();
				}
			}
		});
		RootPanel.get("titleContainer").add(loginComposite);
		RootPanel.get("footerContainer").add(new Footer());
	}
	
	private void clearMainPanel() {
		mainPanel.clear();
	}
	
	private void showTop() {
		if (top == null) {
			top  = new TopPage();
		}
		mainPanel.add(top);
	}
	private void showProfile() {
		if (profile == null) {
			profile  = new ProfileMain();
		}
		mainPanel.add(profile);
	}
	private void showMyData() {
		if (dataManage == null) {
			dataManage = new DataManageMain();
		}
		mainPanel.add(dataManage);
	}
	
	private void showCommunity() {
		if (communityMain == null) {
			communityMain = new CommunityMain();
		}
		mainPanel.add(communityMain);
	}
	
	private void showMessage() {
		
	}

	private void showFriends() {

	}
}
